<html>
<head><meta charset="utf-8"><title>rust/x86 wasm interpreter · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html">rust/x86 wasm interpreter</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198603896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198603896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198603896">(May 24 2020 at 22:52)</a>:</h4>
<p>On Rust/x86, what is the fastest interpreter? (mostly for doing a bunch of f32 tensor ops)</p>



<a name="198687797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198687797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198687797">(May 25 2020 at 17:08)</a>:</h4>
<p>Fastest interpreter, or fastest wasm runtime period? Do you need something that interprets, or can it JIT or AOT?</p>



<a name="198692121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198692121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198692121">(May 25 2020 at 18:21)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span>  : Great clarification. It does not need to be interpreted. Fastest period. AOT / JJIT is fine.</p>



<a name="198692139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198692139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198692139">(May 25 2020 at 18:21)</a>:</h4>
<p>Then I would suggest lucet.</p>



<a name="198692147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198692147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198692147">(May 25 2020 at 18:21)</a>:</h4>
<p>It's an AOT compiler.</p>



<a name="198692211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198692211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198692211">(May 25 2020 at 18:22)</a>:</h4>
<p>If you're fine with a JIT, wasmtime is easy to embed, and it's going to get an AOT mode eventually.</p>



<a name="198693365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198693365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198693365">(May 25 2020 at 18:40)</a>:</h4>
<p>Thanks; wasmtime / bytecodealliance seems to show up alot lately.</p>



<a name="198695393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/198695393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#198695393">(May 25 2020 at 19:11)</a>:</h4>
<p>:)</p>



<a name="199833968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199833968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199833968">(Jun 05 2020 at 04:02)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> : When using wasmtime on x86, is there a way to pass a &amp;mut [f32] from Rust to wasmtime, or does wasmtime's linear memory model (and pointers being relative offsets) require we constantly company data back &amp; forth between wasmtime 's heap memory &amp; Rust's heap memory ?</p>



<a name="199836918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199836918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199836918">(Jun 05 2020 at 05:16)</a>:</h4>
<p>You definitely don't need to constantly copy data, and it's possible to access data in place.</p>



<a name="199836927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199836927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199836927">(Jun 05 2020 at 05:17)</a>:</h4>
<p>I don't remember the API for doing so offhand.</p>



<a name="199856854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199856854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199856854">(Jun 05 2020 at 10:10)</a>:</h4>
<p>Can you give me a pointer on what to search for / where to look? Here is my current reasoning:</p>
<ol>
<li>This can no be done via a WAT/WASM instruction, due to the memory model / sandboxing of wasm.</li>
<li>In "rust crate compiled to wasm", we can do a trick where the rust/wasm32 code and the dynamically geneerated wasm32 code "share a heap" by having the same offsets.</li>
<li>It's not clear how to do this on x86.</li>
</ol>
<p>Is this: (1) some wasmtime api? (2) some way of getting rust/x86 and wasm32/wasmtime/x86 to 'have heap that happen to overlap' or (3) via breaking the 'liner memory model'?</p>
<p>(Because, if the rust Vec&lt;f32&gt; is in arbitrary rust managed memory, and wasm32 code running underwasmtime can only access wasmtime managed heaps, and thsoe heaps are reuiqred to be a linear block, then the only logical consequences seem to be:</p>
<p>(1) we have to copy from rust managed heap to wasmtime managed heap or<br>
(2) we have to expose all of Rust's heap to wasm32 running on wasmtime or<br>
(3) there is some way to break the 'linear memory' constraint</p>



<a name="199856890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199856890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> zeroexcuses <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199856890">(Jun 05 2020 at 10:10)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> : ^ forgot to mention you in last msg</p>



<a name="199887362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199887362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199887362">(Jun 05 2020 at 14:51)</a>:</h4>
<p>First, I should point you to the Zulip chat for wasmtime and other wasm-outside-the-browser projects: <a href="https://bytecodealliance.zulipchat.com/">https://bytecodealliance.zulipchat.com/</a></p>



<a name="199887412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199887412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199887412">(Jun 05 2020 at 14:51)</a>:</h4>
<p>That would be the best place to ask this question.</p>



<a name="199887570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199887570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199887570">(Jun 05 2020 at 14:52)</a>:</h4>
<p>You definitely can't expose all of the Rust heap.</p>



<a name="199888056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888056">(Jun 05 2020 at 14:56)</a>:</h4>
<p>It's relatively easy to build an interface that expects to copy a slice or string into or out of linear memory.</p>



<a name="199888161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888161">(Jun 05 2020 at 14:56)</a>:</h4>
<p>It's harder to <em>not</em> copy, but that is a goal.</p>



<a name="199888491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888491">(Jun 05 2020 at 14:58)</a>:</h4>
<p>Another thing you can do is pass an opaque reference, either an <code>anyref</code> or a typed reference using reference types.</p>



<a name="199888542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888542">(Jun 05 2020 at 14:58)</a>:</h4>
<p>And that reference can have functions that operate on it.</p>



<a name="199888709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888709">(Jun 05 2020 at 14:59)</a>:</h4>
<p>Those functions can then get the actual object back from the opaque reference and operate on that.</p>



<a name="199888895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199888895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199888895">(Jun 05 2020 at 15:01)</a>:</h4>
<p>So if you want a slice of floats on the Rust side, and you want wasm to pass it around without copying it, it can then pass it back to a Rust function that can recover the slice object and use it.</p>



<a name="199889546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rust/x86%20wasm%20interpreter/near/199889546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rust.2Fx86.20wasm.20interpreter.html#199889546">(Jun 05 2020 at 15:05)</a>:</h4>
<p>Would that work for you, or do you want the wasm code to directly access the floats in the slice?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>